import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_devices/bruno/src/components/button/brn_normal_button.dart';
import 'package:smart_devices/model/spare_part.dart';
import 'package:smart_devices/params/spare_part.dart';
import 'package:smart_devices/routes/index.dart';
import 'package:smart_devices/ui/draw_under_line.dart';
import 'package:smart_devices/ui/max_line_wrap.dart';
import 'package:smart_devices/ui/scroll_refresh_config.dart';
import 'package:smart_devices/utils/colors.dart';
import 'package:smart_devices/utils/styles.dart';

import 'order_logic.dart';

class OrderComponent extends GetView<OrderLogic> {
  OrderComponent({super.key}) {
    Get.lazyPut(() => OrderLogic());
  }

  @override
  Widget build(BuildContext context) {
    return Obx(() => scrollRefreshConfig(context));
  }

  Widget scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: controller.refreshController,
      onRefresh: controller.onRefresh,
      onLoading: controller.onLoading,
      child: listViewBuilder(context),
    );
  }

  Widget listViewBuilder(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext c, int index) {
        return DrawUnderLine(
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 15),
            margin:
                index == 0 ? const EdgeInsets.only(top: 15) : EdgeInsets.zero,
            decoration: const BoxDecoration(color: Colors.white),
            child: Column(
              children: [
                Container(
                  height: 40,
                  alignment: Alignment.centerLeft,
                  child: Text(
                    controller.pageList[index].title,
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.color0052,
                        fontSize: 16,
                        fontWeight: FontWeight.w700),
                  ),
                ),
                Container(
                  height: 30,
                  alignment: Alignment.centerLeft,
                  child: MaxLineWrap(
                    maxLine: 1,
                    itemAlignment: MaxLineWrapAlignment.start,
                    children: [
                      Text(
                        '维修单号',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color3333, fontSize: 13),
                      ),
                      Text(
                        controller.pageList[index].orderNo,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorAaaa, fontSize: 13),
                      )
                    ],
                  ),
                ),
                Container(
                  height: 30,
                  alignment: Alignment.centerLeft,
                  child: MaxLineWrap(
                    maxLine: 1,
                    itemAlignment: MaxLineWrapAlignment.start,
                    children: [
                      Text(
                        '设备名称',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color3333, fontSize: 13),
                      ),
                      Text(
                        controller.pageList[index].name,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorAaaa, fontSize: 13),
                      )
                    ],
                  ),
                ),
                Container(
                  height: 30,
                  alignment: Alignment.centerLeft,
                  child: MaxLineWrap(
                    maxLine: 1,
                    itemAlignment: MaxLineWrapAlignment.start,
                    children: [
                      Text(
                        '设备编号',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color3333, fontSize: 13),
                      ),
                      Text(
                        controller.pageList[index].code,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorAaaa, fontSize: 13),
                      )
                    ],
                  ),
                ),
                Container(
                  height: 30,
                  alignment: Alignment.centerLeft,
                  child: MaxLineWrap(
                    maxLine: 1,
                    itemAlignment: MaxLineWrapAlignment.start,
                    children: [
                      Text(
                        '存放位置',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color3333, fontSize: 13),
                      ),
                      Text(
                        controller.pageList[index].orderNo,
                        overflow: TextOverflow.ellipsis,
                        maxLines: 1,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorAaaa, fontSize: 13),
                      )
                    ],
                  ),
                ),
                Container(
                  height: 30,
                  alignment: Alignment.centerLeft,
                  child: MaxLineWrap(
                    maxLine: 1,
                    itemAlignment: MaxLineWrapAlignment.start,
                    children: [
                      Text(
                        '紧急程度',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color3333, fontSize: 13),
                      ),
                      Text(
                        controller.pageList[index].degree.label,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorAaaa, fontSize: 13),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: 40,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        controller.pageList[index].addTime,
                        style: StylesUtils.customTextStyle(
                            fontSize: 13, color: ColorsUtils.color3333),
                      ),
                      BrnNormalButton(
                        onTap: () {
                          Get.toNamed(Routes.deviceRepairInfo, arguments: {
                            'order': controller.pageList[index],
                            'details': SparePartModel(
                                imgUrl:
                                    'https://cdn7.axureshop.com/demo2023/2163241/images/常用组件/u2103.jpg',
                                name: '备件00100',
                                code: 'SB179001',
                                model: '30*50*20',
                                unit: SparePartUnitEnum.all,
                                type: SparePartTypeEnum.main,
                                change: 12,
                                inventory: 15,
                                count: 36),
                          });
                        },
                        constraints:
                            const BoxConstraints.expand(width: 60, height: 25),
                        text: controller.pageList[index].status.label,
                        textStyle: StylesUtils.customTextStyle(
                            fontSize: 12, color: ColorsUtils.color0052),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      },
      itemCount: controller.pageList.length,
      itemExtent: 250,
    );
  }
}
